package com.hongning.railway.ui.main.mine.partcheck.itemviewmodel;

import android.databinding.ObservableArrayList;
import android.databinding.ObservableField;
import android.databinding.ObservableList;
import android.os.Bundle;
import android.support.annotation.NonNull;

import com.hongning.railway.R;
import com.hongning.railway.app.Constant;
import com.hongning.railway.entity.resbean.ResKaoHeBean;
import com.hongning.railway.ui.main.mine.partcheck.PartCheckSecondFragmentViewModel;
import com.hongning.railway.ui.main.mine.partcheck.PartyCheckDetailFragment;
import com.hongning.railway.util.GsonUtil;

import java.util.List;

import me.goldze.mvvmhabit.base.ItemViewModel;
import me.goldze.mvvmhabit.binding.command.BindingAction;
import me.goldze.mvvmhabit.binding.command.BindingCommand;
import me.tatarka.bindingcollectionadapter2.BR;
import me.tatarka.bindingcollectionadapter2.ItemBinding;

public class PartCheckSecondItemViewModel extends ItemViewModel<PartCheckSecondFragmentViewModel> {
    public ItemBinding<CheckScoreItemViewModel> itemBinding = ItemBinding.of(BR.viewModel, R.layout.item_score_info);
    public ObservableList<CheckScoreItemViewModel> viewlist = new ObservableArrayList<>();
    public ObservableField<String> groupName = new ObservableField<>();
    public ObservableField<String> score = new ObservableField<>();
    private ResKaoHeBean mResKaoHeBean;
    public PartCheckSecondItemViewModel(@NonNull PartCheckSecondFragmentViewModel viewModel, ResKaoHeBean dataBean) {
        super(viewModel);
        groupName.set(dataBean.getGroupName());
        score.set(dataBean.getTotleScore()+"");
        this.mResKaoHeBean=dataBean;
        List<ResKaoHeBean.DataBean> result=  GsonUtil.getObjectList(dataBean.getDetails(),ResKaoHeBean.DataBean.class);
        for (ResKaoHeBean.DataBean data:result){
            viewlist.add(new CheckScoreItemViewModel(viewModel,data));
        }

    }
    public BindingCommand itemClick = new BindingCommand(new BindingAction() {
        @Override
        public void call() {
            Bundle bundle = new Bundle();
            bundle.putParcelable(Constant.EXTRA_DATA,mResKaoHeBean);
            viewModel.startContainerActivity(PartyCheckDetailFragment.class.getCanonicalName(),bundle);
        }
    });

}
